2  bulkTCRseq: Plot clonotype counts at the post-vaccine timepoint

2.1 Set up workspace

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ readr     2.1.5
✔ ggplot2   3.5.1     ✔ stringr   1.5.1
✔ lubridate 1.9.4     ✔ tibble    3.2.1
✔ purrr     1.0.4     ✔ tidyr     1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(patchwork)

# Function to assign each clone from a dataframe with specific counts
assign_counts_grp <- function(betas_typed_df){
  betas_typed_df <- betas_typed_df %>%
    dplyr::rename("umi" = 7) %>%
    mutate(PostVax_counts = case_when(umi == 1 ~ "1",
                                     umi > 1 & umi <= 3 ~ "2-3",
                                     umi > 3 & umi <= 10 ~ "4-10",
                                     umi > 10 & umi <= 30  ~ "11-30",
                                     umi > 30 & umi <= 100 ~ "31-100",
                                     umi > 100 ~ "100-MAX")) %>%
    select(Beta_clonotype, Patient, Type, PostVax_counts)
  return(betas_typed_df)
}

2.2 Load data

p101_betas_typed <- read.csv("p101_betas_merged_typed_Part3.csv")
p103_betas_typed <- read.csv("p103_betas_merged_typed_Part3.csv")
p104_betas_typed <- read.csv("p104_betas_merged_typed_Part3.csv")
p105_betas_typed <- read.csv("p105_betas_merged_typed_Part3.csv")
p106_betas_typed <- read.csv("p106_betas_merged_typed_Part3.csv")
p108_betas_typed <- read.csv("p108_betas_merged_typed_Part3.csv")
p109_betas_typed <- read.csv("p109_betas_merged_typed_Part3.csv")
p110_betas_typed <- read.csv("p110_betas_merged_typed_Part3.csv")
p111_betas_typed <- read.csv("p111_betas_merged_typed_Part3.csv")

2.3 Calculate and plot clonotype counts at the post-vaccine timepoint

assigned_p101_postvax <- assign_counts_grp(p101_betas_typed)
assigned_p103_postvax <- assign_counts_grp(p103_betas_typed)
assigned_p104_postvax <- assign_counts_grp(p104_betas_typed)
assigned_p105_postvax <- assign_counts_grp(p105_betas_typed)
assigned_p106_postvax <- assign_counts_grp(p106_betas_typed)
assigned_p108_postvax <- assign_counts_grp(p108_betas_typed)
assigned_p109_postvax <- assign_counts_grp(p109_betas_typed)
assigned_p110_postvax <- assign_counts_grp(p110_betas_typed)
assigned_p111_postvax <- assign_counts_grp(p111_betas_typed)

full <- rbind(assigned_p101_postvax, assigned_p103_postvax,
              assigned_p104_postvax, assigned_p105_postvax, assigned_p106_postvax, assigned_p108_postvax, assigned_p109_postvax, assigned_p110_postvax, assigned_p111_postvax)  %>%
  mutate(Type = factor(Type, levels = c("Other", "Existing", "Post-Nivolumab", "Post-Vaccine")),
         PostVax_counts = factor(PostVax_counts, levels = c("1", "2-3", "4-10", "11-30", "31-100", "100-MAX")),
         Type_PostVax_counts = paste0(Type, ":", PostVax_counts),
         Type_PostVax_counts = factor(Type_PostVax_counts, 
                                      levels = c("Existing:1", "Existing:2-3", "Existing:4-10", "Existing:11-30", "Existing:31-100", "Existing:100-MAX",
                                                 "Post-Nivolumab:1", "Post-Nivolumab:2-3", "Post-Nivolumab:4-10", "Post-Nivolumab:11-30", "Post-Nivolumab:31-100", "Post-Nivolumab:100-MAX",
                                                 "Post-Vaccine:1", "Post-Vaccine:2-3", "Post-Vaccine:4-10", "Post-Vaccine:11-30", "Post-Vaccine:31-100", "Post-Vaccine:100-MAX")))

prop_bc <- full %>%
  group_by(Patient, Type, Type_PostVax_counts) %>%
  dplyr::count() %>%
  filter(Type != "Other") %>%
  ggplot(aes(x = Patient, y = n, fill = Type_PostVax_counts)) +
  geom_col(position = "fill") +
  scale_fill_manual(name = "Clonotype counts at the\npost-vaccine timepoint", values = c(colorRampPalette(c("grey95", "grey70"))(6), colorRampPalette(c("#f9df9e", "darkgoldenrod3"))(6), colorRampPalette(c("#C0E8FF", "#0072B2"))(5))) +
  ylab("Proportion of Clones") +
  theme_classic() +
  theme(plot.title = element_text(hjust=0.5))

prop_bc

2.4 Get session info

sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Rocky Linux 8.10 (Green Obsidian)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.15.so;  LAPACK version 3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/New_York
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] patchwork_1.3.0 lubridate_1.9.4 forcats_1.0.0   stringr_1.5.1  
 [5] purrr_1.0.4     readr_2.1.5     tidyr_1.3.1     tibble_3.2.1   
 [9] ggplot2_3.5.1   tidyverse_2.0.0 dplyr_1.1.4    

loaded via a namespace (and not attached):
 [1] gtable_0.3.6      jsonlite_1.8.9    compiler_4.3.2    tidyselect_1.2.1 
 [5] scales_1.3.0      fastmap_1.2.0     R6_2.6.1          labeling_0.4.3   
 [9] generics_0.1.3    knitr_1.49        htmlwidgets_1.6.4 munsell_0.5.1    
[13] pillar_1.10.1     tzdb_0.5.0        rlang_1.1.5       stringi_1.8.4    
[17] xfun_0.50         timechange_0.3.0  cli_3.6.3         withr_3.0.2      
[21] magrittr_2.0.3    digest_0.6.37     grid_4.3.2        rstudioapi_0.17.1
[25] hms_1.1.3         lifecycle_1.0.4   vctrs_0.6.5       evaluate_1.0.1   
[29] glue_1.8.0        farver_2.1.2      colorspace_2.1-1  rmarkdown_2.29   
[33] tools_4.3.2       pkgconfig_2.0.3   htmltools_0.5.8.1